<?php

namespace app\admin\controller\project;

use app\admin\controller\Base;
use think\Db;

/**
 * 用户组管理
 * Class GroupController
 * @package app\admin\controller\auth
 */
class Projectlog extends Base
{


    public function index()
    {
        $post = $this->request->param();
        $this->assign('project_id', $post['project_id']);
        return view();
    }


    public function loglists()
    {
        $map = array();
        $data = array();
        $post = $this->request->param();
        $map[] = ['wx_msg.project_id', '=', $post['project_id']];
        $data['count'] = Db::view('wx_msg', 'id,project_id,model_id,info,model_status,stories_id,c_time,uid')
            ->view('admin', 'nickname', 'wx_msg.uid=admin.id', 'LEFT')
            ->view('stories','title','wx_msg.stories_id=stories.id','LEFT')
            ->view('doc',['title'=>'doc_title'],'wx_msg.stories_id=doc.id','LEFT')
            ->where($map)
            ->count();
        $data['data'] = Db::view('wx_msg', 'id,project_id,model_id,info,model_status,stories_id,c_time,uid')
            ->view('admin', 'nickname', 'wx_msg.uid=admin.id', 'LEFT')
            ->view('stories','title','wx_msg.stories_id=stories.id','LEFT')
            ->view('doc',['title'=>'doc_title'],'wx_msg.stories_id=doc.id','LEFT')
            ->where($map)
            // ->fetchSql(true)
            ->order('id desc')->page(input("param.page"), input('param.limit'))->select();
        $project_model = config('param.project_model');
        foreach ($data['data'] as &$info) {
            $info2='';
            if ($info['model_id'] < 4) {
                $info['model_name'] = $project_model[$info['model_id']];
            } else {
                $info['model_name'] = '文档';
                $info['title']=$info['doc_title'];
            }
            $info['c_time'] == 0 ? $info['c_time'] = '--' : $info['c_time'] = date('Y-m-d H:i:s', $info['c_time']);
            $info['info']=strip_tags($info['info']);
        }

        if ($data['count'] > 0 && $data['data']) {
            $data['msg'] = '获取成功';
        } else {
            $data['msg'] = '获取数据为空';
        }
        $data['code'] = 0;
        return json($data);
    }

}